class Solution {
public:
    int leastBricks(vector<vector<int>>& wall) {
        int m = wall.size();
        unordered_map<long long, int> posCount;
        for(int row = 0; row < m; ++row)
        {
            long long end = 0;
            int rowSize = wall[row].size();
            for(int i = 0; i < rowSize - 1; ++i)
            {
                end += wall[row][i];
                posCount[end] += 1;
            }
        }
        int maxSpace = 0;
        for(auto& [pos, space] : posCount)
        {
            maxSpace = max(maxSpace, space);
        }
        return m - maxSpace;
    }
};